package shell

import (
	"strings"
)

func (d DeviceShell) am(args ...string) ([]byte, error) {
	return d.RunSync("am", args...)
}

// ForceStopPackage executes force stop the package
func (d DeviceShell) ForceStopPackage(pkgName string) ([]byte, error) {
	return d.am("force-stop", pkgName)
}

// InstrumentClassMethod executes instrumentation test with class#method where classMethod is testPkg.class#method
// and runner is testPkg/androidx.test.runner.AndroidJUnitRunner
func (d DeviceShell) InstrumentClassMethod(classMethod string, runner string) ([]byte, error) {
	return d.InstrumentClassMethodParams(nil, classMethod, runner)
}

// InstrumentClassMethodParams executes instrumentation test with arguments and class#method where classMethod is testPkg.class#method
// and runner is testPkg/androidx.test.runner.AndroidJUnitRunner
func (d DeviceShell) InstrumentClassMethodParams(params map[string]string, classMethod string, runner string) ([]byte, error) {
	var args []string
	for k, v := range params {
		args = append(args, "-e", k, v)
	}
	return d.am("instrument", "-w", strings.Join(args, " "), "-e", "class", classMethod, runner)
}
